package org.rsbot.event.impl;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import org.rsbot.bot.Bot;
import org.rsbot.event.listeners.PaintListener;
import org.rsbot.script.methods.Calculations;
import org.rsbot.script.methods.Game;
import org.rsbot.script.methods.GroundItems;
import org.rsbot.script.methods.MethodContext;
import org.rsbot.script.methods.Players;
import org.rsbot.script.wrappers.RSGroundItem;
import org.rsbot.script.wrappers.RSItem;
import org.rsbot.script.wrappers.RSPlayer;
import org.rsbot.script.wrappers.RSTile;

public class DrawGround
  implements PaintListener
{
  private MethodContext ctx;

  public DrawGround(Bot paramBot)
  {
    this.ctx = paramBot.getMethodContext();
  }

  public void onRepaint(Graphics paramGraphics) {
    if (!this.ctx.game.isLoggedIn())
      return;
    RSPlayer localRSPlayer = this.ctx.players.getMyPlayer();
    if (localRSPlayer == null)
      return;
    paramGraphics.setColor(Color.WHITE);
    RSTile localRSTile = localRSPlayer.getLocation();
    for (int i = localRSTile.getX() - 25; i < localRSTile.getX() + 25; i++)
      for (int j = localRSTile.getY() - 25; j < localRSTile.getY() + 25; j++) {
        RSGroundItem[] arrayOfRSGroundItem = this.ctx.groundItems.getAllAt(i, j);
        if ((arrayOfRSGroundItem == null) || (arrayOfRSGroundItem.length == 0)) {
          continue;
        }
        Point localPoint = this.ctx.calc.tileToScreen(arrayOfRSGroundItem[0].getLocation());
        if (this.ctx.calc.pointOnScreen(localPoint))
          paramGraphics.drawString("" + arrayOfRSGroundItem[0].getItem().getID(), localRSTile.getX() - 10, localRSTile.getY());
      }
  }
}